package com.atguigu.tingshu.search.api;

import com.atguigu.tingshu.common.constant.RedisConstant;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.search.AlbumInfoIndex;
import com.atguigu.tingshu.query.album.AlbumInfoQuery;
import com.atguigu.tingshu.query.search.AlbumIndexQuery;
import com.atguigu.tingshu.search.service.SearchService;
import com.atguigu.tingshu.vo.search.AlbumSearchResponseVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.redisson.api.RBloomFilter;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Tag(name = "搜索专辑管理")
@RestController
@RequestMapping("api/search/albumInfo")
@SuppressWarnings({"all"})
public class SearchApiController {

    @Autowired
    private SearchService searchService;

    /**
     * 专辑上架
     */
    @Operation(summary = "专辑上架")
    @GetMapping("/upperAlbum/{albumId}")
    public Result upperAlbum(@PathVariable Long albumId) {
        searchService.upperAlbum(albumId);
        return Result.ok();
    }
    /**
     * 专辑下架
     */
    @Operation(summary = "专辑下架")
    @GetMapping("lowerAlbum/{albumId}")
    public Result lowerAlbum(@PathVariable Long albumId) {
        searchService.lowerAlbum(albumId);
        return Result.ok();
    }

    @Operation(summary = "批量上架专辑")
    @GetMapping("batchUpperAlbum")
    public Result getAlbumInfdo() {
        for (int i = 1; i <= 1500; i++) {
            searchService.upperAlbum(Long.valueOf(i));
        }
        return Result.ok();
    }

//http://127.0.0.1/api/search/albumInfo
    @Operation(summary = "根据关键字检索")
    @PostMapping
    public Result search(@RequestBody AlbumIndexQuery albumIndexQuery) {
        AlbumSearchResponseVo albumSearchResponseVo = searchService.search(albumIndexQuery);
        return Result.ok(albumSearchResponseVo);
    }
//http://127.0.0.1/api/search/albumInfo/channel/1
    @Operation(summary = "根据一级分类id查看所有的三级分类对应的专辑")
    @GetMapping("/channel/{category1Id}")
    public Result channel(@PathVariable Long category1Id) {
        List<Map<String, Object>> map = searchService.channel(category1Id);
        return Result.ok(map);
    }

//    http://127.0.0.1/api/search/albumInfo/completeSuggest/%E6%92%92%E6%97%A6%E8%BF%99%E4%BA%9B
    @Operation(summary = "搜索自动补全")
    @GetMapping("/completeSuggest/{keyword}")
    public Result completeSuggest(@PathVariable("keyword") String keyword){
        List<String> list =  searchService.completeSuggest(keyword);
        return Result.ok(list);
    }

    @Operation(summary = "更新排行榜")
    @GetMapping("/updateLatelyAlbumRanking")
    public Result updateLatelyAlbumRanking(){
        searchService.updateLatelyAlbumRanking();
        return Result.ok();
    }
//    http://127.0.0.1/api/search/albumInfo/findRankingList/1/hotScore
    @Operation(summary = "获取排行榜")
    @GetMapping("/findRankingList/{category1Id}/{statType}")
    public Result findRankingList(@PathVariable("category1Id") Long category1Id,
                                  @PathVariable("statType") String statType){
         List<AlbumInfoIndex> list = searchService.findRankingList(category1Id,statType);
        return Result.ok(list);
    }
}

